import merge from 'webpack-merge'
import { WeiboActions } from '../actions'
const { WeiboTypes } = WeiboActions

const webo_state = {
  form: {
    loading: false
  },
  users: {
    loading: false,
    select: '',
    show: false,
    list: []
  },
  articles: {
    loading: false,
    select: '',
    show: false,
    list: []
  },
  comments: {
    loading: false,
    show: false,
    list: []
  }
}

const WeiboState = (state = webo_state, action) => {
  switch (action.type) {
    case WeiboTypes.set_init:
      return webo_state
    case WeiboTypes.set_loading:
      const { loading, loadingType } = action
      const loading_state = merge({}, state)
      loading_state[loadingType]['loading'] = loading
      return loading_state
    case WeiboTypes.set_show:
      const { show, showType } = action
      console.log('show, showType', show, showType)
      const show_state = merge({}, state)
      show_state[showType]['show'] = show
      return show_state
    case WeiboTypes.set_select:
      const { selectId, selectType } = action
      const select_state = merge({}, state)
      select_state[selectType]['select'] = selectId
      return select_state
    case WeiboTypes.set_users:
      const { users } = action
      const user_state = merge({}, state)
      user_state.users.list = users
      return user_state
    case WeiboTypes.set_articles:
      const { articles } = action
      const article_state = merge({}, state)
      article_state.articles.list = articles
      return article_state
    case WeiboTypes.set_comments:
      const { comments } = action
      const comment_state = merge({}, state)
      comment_state.comments.list = comments
      return comment_state
    default:
      return state
  }
}

export default WeiboState
